﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using CoreEx.Database.Client;
using LinFu.IoC.Configuration;
using LinFu.IoC.Interfaces;
using LinFu.IoC.Configuration;

namespace CoreEx.Database.Client.Implementation
{
    
    public class ParameterCache : IParameterCache
    {
        private IDictionary<string,IEnumerable<IDataParameter>> _parameters 
            = new Dictionary<string, IEnumerable<IDataParameter>>();


        private readonly object syncLock = new object();

        

        public IEnumerable<IDataParameter> GetParameters(string procedureName)
        {
            lock(syncLock)
            {
                if (!_parameters.ContainsKey(procedureName))
                     _parameters.Add(procedureName, ParameterExtractor.GetParameters(procedureName));

                return _parameters[procedureName].Cast<ICloneable>().Select(p => (IDataParameter) p.Clone());            
            }
            
        }

        public IParameterExtractor ParameterExtractor { get; set;}
       
    }
}
